<?php
/**
 * Created by PhpStorm.
 * User: jungshen
 * Date: 2018/10/16
 * Time: 17:52
 */

namespace app\api\controller\other;


use app\api\controller\BasicApi;
use think\Db;
use think\Exception;

class User extends BasicApi
{
    /**
     * 获取用户案例列表
     * @return \think\response\Json
     */
    public function case_list(){
        try{
            $mid=input('mid');
            $db=Db::name('member_case')->where('mid',$mid)->where('status',1)->hidden('status,mid,updatetime');
            $list=$db->select();
            foreach ($list as $k=>&$v){
                $v['images']=explode('|',$v['images']);
                $v['image']=$v['images'][0];
                $v['addtime']=date('Y-m-d',$v['addtime']);
            }
            return json(['msg'=>'success','data'=>$list]);
        }catch(Exception $e){
            return json(['msg'=>$e->getMessage()],500);
        }
    }
    /**
     * 获取案例详细信息
     * @return \think\response\Json
     */
    public function case_info()
    {
        try{
            $id=input('id');
            Db::name('member_case')->where('id',$id)->setInc('borwse');
            $case=Db::name('member_case')->where('id',$id)->where('status',1)->hidden('mid,status,updatetime')->find();
            $case['images']=explode('|',$case['images']);
            $case['image']=$case['images'][0];
            $case['praised']=Db::name('praise')->where('attach_id',$case['id'])->where('type',1)->count();
            return json(['msg'=>'success','data'=>$case]);
        }catch (Exception $e){
            return json(['msg'=>$e->getMessage()],500);
        }
    }
}